package com.example.student.controller;

import com.example.student.domain.Course;
import com.example.student.service.CourseService;
import com.example.student.util.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/course")
public class CourseController {
    @Autowired
    CourseService courseService;

    @RequestMapping("/getCourseList")
    @ResponseBody
    public PageBean<Course> getCourseList(@RequestParam Integer page, @RequestParam Integer rows, String courseName) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("pageno",page);
        map.put("pagesize",rows);
        map.put("username",courseName);

        PageBean<Course> datas = courseService.queryPage(map);
        System.out.println("datas = " + datas);
        return  datas;
    }

    @RequestMapping("/addCourse")
    public Integer addCourse(Course course) {
        int isSuccess = courseService.addCourse(course);
        return isSuccess;
    }
}
